package com.ruoyi.web.controller.statistic.counsellor;


import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.statistic.domain.StatisticStudentBaseInfo;
import com.ruoyi.statistic.domain.vo.StatisticStudentListSearchVo;
import com.ruoyi.statistic.service.IStatisticStudentBaseInfoService;
import com.ruoyi.statistic.service.IStatisticStudentEmploymentFileService;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RestController("CounsellorStatisticStudentBaseInfoController")
@RequestMapping("/counsellor/employment/statistic/student/baseInfo")
public class StatisticStudentBaseInfoController extends BaseController {

    @Resource
    private IStatisticStudentBaseInfoService statisticStudentBaseInfoService;


    private IStatisticStudentEmploymentFileService statisticStudentEmploymentFileService;

    @Resource
    private ISysConfigService configService;

    @Resource
    private RedisCache redisCache;


    /**
     * 查询统计学生列表(辅导员)
     */
    @GetMapping("/list")
    public TableDataInfo list(StatisticStudentListSearchVo vo) {
        String code = getUsername();
        vo.setCounsellorCode(Arrays.asList(code.split(" ")));
        startPage();
        List<StatisticStudentBaseInfo> list = statisticStudentBaseInfoService.selectCounsellorStatisticStudentBaseInfoListBySearchVo(vo);
        return getDataTable(list);
    }


    /**
     * 导出学生管理列表（辅导员）
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, StatisticStudentListSearchVo vo) {
        String code = getUsername();
        vo.setCounsellorCode(Arrays.asList(code.split(" ")));
        List<StatisticStudentBaseInfo> list = statisticStudentBaseInfoService.selectCounsellorStatisticStudentBaseInfoListBySearchVo(vo);
        ExcelUtil<StatisticStudentBaseInfo> util = new ExcelUtil<>(StatisticStudentBaseInfo.class);
        util.exportExcel(response, list, "学生管理数据");
    }


    /**
     * 获取学生管理详细信息（辅导员）
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        String code = getUsername();
        StatisticStudentBaseInfo statisticStudentBaseInfo = statisticStudentBaseInfoService.selectStatisticStudentBaseInfoById(id);
        if (ObjectUtil.isEmpty(statisticStudentBaseInfo)){
            return error("未查询到当前学生");
        }
        if (!statisticStudentBaseInfo.getCounsellorCode().equals(code)){
            return error("暂无权限");
        }
        return success(statisticStudentBaseInfoService.selectStatisticStudentBaseInfoById(id));
    }



}
